<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>精美注册页面</title>
  <!-- 引入Element UI的样式 -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <script src="vue.js"></script>
    <script src="axios.js"></script>
    <script src="elementui.js"></script>
  <style>
    /* 页面整体背景及布局样式 */
    body {
      margin: 0;
      padding: 0;
      background-color: #f8f0f5; /* 柔和的背景底色 */
      font-family: Arial, sans-serif;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
    }

    /* 注册页面主体容器样式 */
  .register-container {
      width: 450px;
      background-color: white;
      border-radius: 10px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
      padding: 30px;
    }

    /* 标题样式 */
  .register-title {
      font-size: 24px;
      font-weight: bold;
      color: #333;
      text-align: center;
      margin-bottom: 25px;
    }

    /* Element UI表单样式调整 */
  .el-form {
      width: 100%;
    }

   .el-form-item {
      margin-bottom: 20px;
    }

   .el-form-item__label {
      width: 80px;
      text-align: right;
      font-size: 14px;
      color: #666;
    }

   .el-input__inner {
      width: calc(100% - 80px);
    }

    /* 按钮样式 */
  .register-btn-group {
      text-align: center;
      margin-top: 20px;
    }

   .register-btn {
      width: 120px;
      margin: 0 10px;
    }

   .register-btn-primary {
      background-color: #67C23A; /* 绿色主题色 */
      color: white;
    }

   .register-btn-default {
      background-color: #E4E7ED; /* 灰色背景色 */
      color: #606266;
    }

    /* 鼠标悬停按钮效果 */
   .register-btn:hover {
      opacity: 0.8;
      cursor: pointer;
    }

    /* 底部提示信息样式 */
   .register-tip {
      font-size: 12px;
      color: #999;
      text-align: center;
      margin-top: 15px;
    }
  </style>
</head>

<body>
  <div id="app" class="register-container">
    <h2 class="register-title">用户注册</h2>
    <el-form ref="registerForm" :model="registerForm">
      <el-form-item label="用户名" prop="uname">
        <el-input v-model="registerForm.uname" placeholder="请输入中文或英文字母组成的用户名"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="upwd">
        <el-input type="password" v-model="registerForm.upwd" placeholder="请设置6-16位密码"></el-input>
      </el-form-item>
      <!-- <el-form-item label="确认密码" prop="confirmPassword">
        <el-input type="password" v-model="registerForm.confirmPassword" placeholder="请再次输入密码"></el-input>
      </el-form-item>
       -->
     
      <div class="register-btn-group">
        <el-button type="primary" class="register-btn register-btn-primary" @click="submitUser">注册</el-button>
        <el-button type="default" class="register-btn register-btn-default" @click="resetForm('registerForm')">重置</el-button>
      </div>
    </el-form>
    <p class="register-tip">已有账号？ <a href="#">立即登录</a></p>
  </div>

  <!-- 引入Vue.js -->
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
  <!-- 引入Element UI的JavaScript代码 -->
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <script>
    new Vue({
      el: '#app',
      data: {
          registerForm: {
            id:0,
            uname: '',
            upwd: '',
            confirmPassword: ''
          },
      },
      methods: {
        // 创建一个随机数作为用户Id
        generateUserId() {
          return Math.floor(Math.random() * 1000000);
        },
        submitUser() {
            this.registerForm.id=this.generateUserId()
            axios.post('http://localhost:8080/db/registerUser',this.registerForm)
                .then(response => {

                  alert('注册成功', response);
                  // 注册成功后跳转到登录页面
                  window.location.href = 'login.html';
                  this.registerForm={};
                })
                .catch(error => {
                    alert('注册失败', error);
                });
        },
        resetForm(formName) {
          this.$refs[formName].resetFields();
        }
      }
    });
  </script>
</body>

</html>